﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Glucometer
{
    public partial class BlinkingDateTimeControl : UserControl
    {
        List<BlinkingLabel> blinkingLabelList;

        int currentBlinkPosition = -1;

        public BlinkingDateTimeControl()
        {
            InitializeComponent();

            blinkingLabelList = new List<BlinkingLabel>();

            //int height = 20;
            //int width = 9;
            //Size s = new Size(width, height);

            //int location_x = 0;
            //int location_y = 0;

            //int totalsize = 0;

            for (int i = 0; i < 14; i++)
            {
                BlinkingLabel lbl = new BlinkingLabel();
                //lbl.Size = s;
                lbl.Width = this.Size.Width / 36;
                //lbl.Location = new Point(location_x, location_y);
                //location_x += width;
                //totalsize += width;

                lbl.Dock = System.Windows.Forms.DockStyle.Right;

                if (i == 2 || i == 5)
                    lbl.Text = "/";
                else if (i == 8)
                    lbl.Text = "";
                else if (i == 11)
                    lbl.Text = ":";
                else
                {
                    lbl.Text = i.ToString();
                    blinkingLabelList.Add(lbl);
                }
                this.Controls.Add(lbl);
            }

            //this.Size = new Size(totalsize, height);
        }

        public void BlinkPosition(int i)
        {
            stopBlinking();

            if (i >= 0 && i < blinkingLabelList.Count)
            {
                blinkingLabelList[i].startBlinking(2);
                currentBlinkPosition = i;
            }
            else if (i < 0)
            {
                currentBlinkPosition = -1;
            }
        }

        public void StopAllBlinking()
        {
            foreach (BlinkingLabel lbl in blinkingLabelList)
                lbl.stopBlinking();
        }

        public void stopBlinking()
        {
            if (currentBlinkPosition >= 0)
                blinkingLabelList[currentBlinkPosition].stopBlinking();
        }

        public void setDateTime(DateTime dt)
        {
            int year = dt.Year - 2000;
            int month = dt.Month;
            int day = dt.Day;

            int hour = dt.Hour;
            int minute = dt.Minute;

            //SETTING YEAR
            blinkingLabelList[0].Text =  (year/10).ToString();
            blinkingLabelList[1].Text = (year % 10).ToString();

            //SETTING MONTH
            blinkingLabelList[2].Text = (month / 10).ToString();
            blinkingLabelList[3].Text = (month % 10).ToString();

            //SETTING DAY
            blinkingLabelList[4].Text = (day / 10).ToString();
            blinkingLabelList[5].Text = (day % 10).ToString();

            //SETTING HOUR
            blinkingLabelList[6].Text = (hour / 10).ToString();
            blinkingLabelList[7].Text = (hour % 10).ToString();

            //SETTING MINUTE
            blinkingLabelList[8].Text = (minute / 10).ToString();
            blinkingLabelList[9].Text = (minute % 10).ToString();

        }

        public void setCurrentPositionDisplay(string c)
        {
            if(currentBlinkPosition >= 0)
                blinkingLabelList[currentBlinkPosition].Text = c.ToString();
        }
    }
}
